/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.yuecai.modules.yc_goods_sku.domain;

import com.yuecai.modules.yc_goods.domain.YcGoods;
import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.ApiModelProperty;
import cn.hutool.core.bean.copier.CopyOptions;
import javax.persistence.*;
import javax.validation.constraints.*;
import java.sql.Timestamp;
import java.math.BigDecimal;
import java.io.Serializable;

/**
* @website https://el-admin.vip
* @description /
* @author dm
* @date 2020-06-29
**/
@Entity
@Data
@Table(name="yc_goods_sku")
public class YcGoodsSku implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    @ApiModelProperty(value = "id")
    private Long id;

    /*@Column(name = "good_id")
    @ApiModelProperty(value = "商品ID")
    private Long goodId;*/

    @Column(name = "spec_values",nullable = false)
    @NotBlank
    @ApiModelProperty(value = "规格")
    private String specValues;

    @Column(name = "stock",nullable = false)
    @NotNull
    @ApiModelProperty(value = "库存")
    private Integer stock;

    @Column(name = "is_for_purchasin",nullable = false)
    @NotNull
    @ApiModelProperty(value = "是否限购，")
    private Boolean isForPurchasin;

    @Column(name = "for_purchasing")
    @ApiModelProperty(value = "限购")
    private Integer forPurchasing;

    @Column(name = "original_price",nullable = false)
    @NotNull
    @ApiModelProperty(value = "原价")
    private BigDecimal originalPrice;


    @Column(name = "sell_price")
    @ApiModelProperty(value = "销售价")
    private BigDecimal sellPrice;

    @Column(name = "image")
    @ApiModelProperty(value = "缩略图")
    private String image;

    @Column(name = "sales")
    @ApiModelProperty(value = "销量")
    private Integer sales;

    @Column(name = "create_time")
    @ApiModelProperty(value = "创建时间")
    private Timestamp createTime;

    @Column(name = "update_time")
    @ApiModelProperty(value = "更新时间")
    private Timestamp updateTime;

    @Column(name = "unit")
    @ApiModelProperty(value = "单位")
    private String unit;

    @Column(name = "unit_price")
    @ApiModelProperty(value = "单价")
    private BigDecimal unitPrice;

    @OneToOne
    @JoinColumn(name = "good_id",referencedColumnName = "id")
    private YcGoods ycGoods;

    public void copy(YcGoodsSku source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}